import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ProgressMonitor;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;





public class comparison implements ActionListener
{
	int mip;
	int dhmip;
	int mhmip;
	volatile Map<Integer, Integer> statistics = new HashMap<Integer, Integer>(5);
	int len;
	
	public static  int comf;
	public static  int comf1;
	public static  int comf2;
	
	DataOutputStream output;

	BufferedInputStream bis;
	
	BufferedOutputStream bos;

	byte[] receivedData;
	int in;
	
	String strLine;
	public Font f = new Font("Times new roman" , Font.BOLD , 16);	
	public Font f1 = new Font("Times new roman", Font.BOLD , 28);
	public Font f2 = new Font("Times new roman", Font.BOLD , 18);
	public Font f3 = new Font("Arial Rounded MT Bold", Font.BOLD , 15);
    public JLabel T1= new JLabel("Mobile Performence And Comparison ");
	public JLabel T2= new JLabel();
	public JLabel l = new JLabel("Received File");

	public JLabel l1 = new JLabel("BandWidth(kbs/ps):");
	public JLabel l2 = new JLabel("Time Delay(ms)     :");
	public JLabel l3= new JLabel("File Size(kbs)         :");
	public JLabel l3a= new JLabel("Prototcol Name     :");
	
	public JLabel l4 = new JLabel("BandWidth(kbs/ps)  :");
	public JLabel l5= new JLabel("Time Delay(ms)       :");
	public JLabel l6= new JLabel("File Size(kbs)           :");
	public JLabel l6a= new JLabel("Prototcol Name       :");
	
	public JLabel l7= new JLabel("MOBILE  INTERNET  PROTOCOL");
	public JLabel l8= new JLabel("DYNAMIC HIERARCHICAL MOBILE INTERNET");
	public JLabel l8a= new JLabel("PROTOCOL");
	public JLabel l9= new JLabel("MULTICAST HIERARCHICAL MOBILE INTERNET");
	public JLabel l9a= new JLabel("PROTOCOL");
	public JLabel l10 = new JLabel("BandWidth(kbs/ps)  :");
	public JLabel l11 = new JLabel("Time Delay(ms)       :");
	public JLabel l12= new JLabel("File Size(kbs)           :");
	public JLabel l12a= new JLabel("Prototcol Name       :");
	//public JLabel l13= new JLabel("Gateway FA    :");
	
	public JButton btn = new JButton("Submit");
	public JTextArea tf = new JTextArea();
	public JScrollPane pane = new JScrollPane();
	public  JProgressBar pbar=new JProgressBar();
	public JProgressBar pbar1=new JProgressBar();
	public JProgressBar pbar2=new JProgressBar();
	
	public JButton graph = new JButton(" Bar Graphical");
	public JButton comparison = new JButton(" Comparison");
	public JTextArea tf1 = new JTextArea();
	public JScrollPane pane1 = new JScrollPane();
	public JTextArea tf2 = new JTextArea();
	public JScrollPane pane2 = new JScrollPane();
	public JTextField txt1 = new JTextField();
	public JTextField txt2 = new JTextField();
	public JTextField txt3 = new JTextField();
	public JTextField txt3a = new JTextField();
	public JTextField txt4 = new JTextField();
	public JTextField txt5 = new JTextField();
	public JTextField txt6 = new JTextField();
	public JTextField txt7 = new JTextField();
	public JTextField txt8 = new JTextField();
	
	public JTextField txt9 = new JTextField();
	public JTextField txt10 = new JTextField();
	public JTextField txt10a = new JTextField();
	
	
	public JFrame jf;
	public Container c;
	JPanel jp=new JPanel();
	JPanel jp1=new JPanel();
	
	JPanel jp2=new JPanel();
	JPanel jp3=new JPanel();
	JPanel jp4=new JPanel();
	JPanel jp5=new JPanel();
	
	JPanel jp6=new JPanel();
	JPanel jp7=new JPanel();
	JPanel jp8=new JPanel();
	JPanel jp9=new JPanel();
	
	comparison()
	{
		
				
		jf = new JFrame("Mobile Server");
		c = jf.getContentPane();
		c.setLayout(null);
		jf.setSize(1080,1080);
		//c.setBackground(new Color(2,62,72));
		//c.setBackground(new Color(5,57,16));
		c.setBackground(new Color(168,167,160));
		//c.setBackground(new Color(242,204,132));
		
		T1.setBounds(300,10,950,50);
		T2.setBounds(210,50,950,50);
		T1.setForeground(Color.RED);
		T2.setForeground(Color.RED);
		
		txt1.setBounds(270,140,170,30);
		txt2.setBounds(270,192,170,30);
		txt3.setBounds(270,240,170,30);
		txt3a.setBounds(270,286,170,30);
		txt4.setBounds(500,420,170,30);
		txt5.setBounds(500,470,170,30);
		txt6.setBounds(500,520,170,30);
		
		txt7.setBounds(500,570,170,30);
		txt8.setBounds(750,150,170,30);
		txt9.setBounds(750,200,170,30);
		txt10.setBounds(750,250,170,30);
		txt10a.setBounds(750,300,170,30);
		
		txt1.setFont(f);
		txt2.setFont(f);
		txt3.setFont(f);
		txt3a.setFont(f);
		txt4.setFont(f);
		txt5.setFont(f);
		txt6.setFont(f);
		txt7.setFont(f);
		txt8.setFont(f);
		txt9.setFont(f);
		txt10.setFont(f);
		txt10a.setFont(f);
		txt1.setForeground(new Color(10,79,6));
		txt2.setForeground(new Color(10,79,6));
		txt3.setForeground(new Color(10,79,6));
		txt3a.setForeground(new Color(10,79,6));
		txt4.setForeground(new Color(10,79,6));
		txt5.setForeground(new Color(10,79,6));
		txt6.setForeground(new Color(10,79,6));
		
		txt7.setForeground(new Color(10,79,6));
		txt8.setForeground(new Color(10,79,6));
		txt9.setForeground(new Color(10,79,6));
		txt10.setForeground(new Color(10,79,6));
		txt10a.setForeground(new Color(10,79,6));
		l.setBounds(720,330,250,35);
		
		l1.setBounds(100,140,250,35);
		l2.setBounds(100,192,250,35);
		l3.setBounds(100,240,250,35);
		l3a.setBounds(100,289,250,35);
		
		l4.setBounds(300,420,170,30);
		l5.setBounds(300,470,170,30);
		l6.setBounds(300,520,170,30);
		l6a.setBounds(300,570,170,30);
		
		l7.setBounds(100,100,350,35);
		l8.setBounds(550,100,550,35);
		l8a.setBounds(670,125,550,35);
		l9.setBounds(300,380,550,35);
		l9a.setBounds(400,400,550,35);
		l10.setBounds(570,150,250,35);
		l11.setBounds(570,200,250,35);
		l12.setBounds(570,250,250,35);
		l12a.setBounds(570,300,250,35);
		
		
		l.setForeground(new Color(6,45,14));
		//l.setForeground(new Color(120,0,0));
		l1.setForeground(new Color(111,13,103));
		l2.setForeground(new Color(111,13,103));
		l3.setForeground(new Color(111,13,103));
		l3a.setForeground(new Color(111,13,103));
		
		l4.setForeground(new Color(120,0,0));
		l5.setForeground(new Color(120,0,0));
		l6.setForeground(new Color(120,0,0));
		l6a.setForeground(new Color(120,0,0));
		
		l7.setForeground(new Color(6,54,18));
		l8.setForeground(new Color(6,54,18));
		l8a.setForeground(new Color(6,54,18));
		l9.setForeground(new Color(6,54,18));
		l9a.setForeground(new Color(6,54,18));
		l10.setForeground(Color.BLUE);
		l11.setForeground(Color.BLUE);
		l12.setForeground(Color.BLUE);
		l12a.setForeground(Color.BLUE);
		
		l.setFont(f2);
		l1.setFont(f2);
		l2.setFont(f2);
		l3.setFont(f2);
		l3a.setFont(f2);
		l4.setFont(f2);
		l5.setFont(f2);
		l6.setFont(f2);
		l6a.setFont(f2);
		l7.setFont(f3);
		l8.setFont(f3);
		l8a.setFont(f3);
		l9.setFont(f3);
		l9a.setFont(f3);
		l10.setFont(f2);
		l11.setFont(f2);
		l12.setFont(f2);
		l12a.setFont(f2);
		
		comparison.setBounds(360,640,150,35);
		comparison.setFont(f2);
	  //  graph.setBackground(new Color(26,230,246));
		comparison.setForeground(new Color(120,0,0));
		
		
		
		graph.setBounds(560,640,150,35);
		graph.setFont(f2);
	  //  graph.setBackground(new Color(26,230,246));
		graph.setForeground(new Color(120,0,0));
		
		//tf.setBackground(new Color(151,242,241));
		tf.setForeground(Color.BLUE);
		tf1.setForeground(new Color(69,39,4));
		tf2.setForeground(new Color(170,5,5));
		
		tf.setFont(f);
		tf1.setFont(f);
		tf2.setFont(f);
		
		jp.setBounds(30,68,960,616);
		//jp.setBackground(Color.GRAY);
		jp.setBackground(new Color(168,167,160));
		jp1.setBackground(Color.DARK_GRAY);
		jp1.setBounds(29,67,962,618);
		
		jp2.setBounds(66,90,400,250);
		//jp2.setBackground(Color.GRAY);
		jp2.setBackground(new Color(168,167,160));
		//jp.setBackground(Color.DARK_GRAY);
		jp3.setBounds(65,89,402,252);
		jp3.setBackground(Color.BLACK);
		
		jp4.setBounds(536,90,400,250);
		//jp2.setBackground(Color.GRAY);
		jp4.setBackground(new Color(168,167,160));
		//jp.setBackground(Color.DARK_GRAY);
		jp5.setBounds(535,89,402,252);
		jp5.setBackground(Color.BLACK);
		
		jp6.setBounds(276,370,430,250);
		//jp2.setBackground(Color.GRAY);
		jp6.setBackground(new Color(168,167,160));
		//jp.setBackground(Color.DARK_GRAY);
		jp7.setBounds(275,369,432,252);
		jp7.setBackground(Color.BLACK);
		
		jp8.setBounds(756,330,400,250);
		//jp2.setBackground(Color.GRAY);
		jp8.setBackground(new Color(168,167,160));
		//jp.setBackground(Color.DARK_GRAY);
		jp9.setBounds(755,329,402,252);
		jp9.setBackground(Color.BLACK);
		
		
		pane.setBackground(new Color(151,242,241));
		tf.setColumns(20);
		tf.setRows(10);
		tf.setName("tf");
		pane.setName("pane");
		pane.setViewportView(tf);
		pane.setBounds(580,363,350,200);
		
        pane1.setBounds(370,330,300,200);
      
       // tf.setBackground(Color.WHITE);
      //  tf1.setBackground(Color.WHITE);
       // tf2.setBackground(Color.WHITE);
        
		tf1.setColumns(20);
		tf1.setRows(10);
		tf1.setName("tf");
		pane1.setName("pane");
		pane1.setViewportView(tf1);
				
		T1.setFont(f1);
		T2.setFont(f1);
			
        pane2.setBounds(700,330,300,200);
		
		tf2.setColumns(20);
		tf2.setRows(10);
		tf2.setName("tf");
		pane2.setName("pane");
		pane2.setViewportView(tf2);
		graph.addActionListener(this);	
		
		comparison.addActionListener(this);
		btn.setMnemonic(KeyEvent.VK_S); 
		jf.show();
		//c.add(pane, BorderLayout.CENTER);
		c.add(T1);
		c.add(txt1);
		c.add(txt2);
		c.add(txt3);
		c.add(txt3a);
		c.add(txt4);
		c.add(txt5);
		c.add(txt6);
		c.add(txt7);
		c.add(txt8);
		c.add(txt9);
		c.add(txt10);
		c.add(txt10a);
	//	c.add(graph);
		
		//c.add(l);
		c.add(l1);
		c.add(l2);
		c.add(l3);
		c.add(l3a);
		c.add(l4);
		c.add(l5);
		c.add(l6);
		c.add(l6a);
		c.add(l7);
		c.add(l8);
		c.add(l8a);
		c.add(l9);
		c.add(l9a);
		c.add(l10);
		c.add(l11);
		c.add(l12);
		c.add(l12a);
		c.add(jp2);
		c.add(jp3);
		c.add(jp4);
		c.add(jp5);
		c.add(jp6);
		c.add(jp7);
		c.add(comparison);
		//c.add(jp9);
		
		c.add(jp);
		c.add(jp1);
		
		
			
		jf.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent win) {
				System.exit(0);
			}
		});		
		
	}
	
	public void updateBar(int newValue) {
	    pbar.setValue(newValue);
	  }
	/* *****************************  end ******************************************** */	

	public static void main(String args[])
	{
		comparison s=new comparison();
		
		
	}
	
	
	
	
	 public void actionPerformed(ActionEvent e)
	 {
		
		 if(e.getSource()==comparison)
		 {
  		 
			 
			try {
				Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
				java.sql.Connection con = DriverManager.getConnection("jdbc:odbc:Mobile");
	             Statement s= con.createStatement();
	            ResultSet rs,rs1;
	            
	             rs =  s.executeQuery("select * from Mobility");
	            while(rs.next())
	            {
	            	//System.out.println("hahaka");
	              String bandwidth = rs.getString(1);
	 			  String Timedelay= rs.getString(2);
	 			  String Filesize=rs.getString(3);
	 			  String Protocol= rs.getString(4);
	 			 System.out.println("protocol name"+Protocol);
	 			 
	 			  if(Protocol.equals("  MIP"))
	 			  {
	 			 txt1.setText(bandwidth);
	 			 
	 		//int str=txt1.getText();
	 	//	int a=Integer.toString(str);
	 			 txt2.setText(Timedelay);
	 			 txt3a.setText(Protocol);
	 			 txt3.setText(Filesize);
	 			 
	 			//mip= Integer.parseInt(bandwidth);
	 			  }
	 			 else if(Protocol.equals("MHMIP"))
	 			  
	 			  {	 
	 				 
	 				 
	 			 txt4.setText(bandwidth);
	 			  			 
	 			 txt5.setText(Timedelay);
	 			 txt7.setText(Protocol);
	 			 txt6.setText(Filesize);
	 			// dhmip= Integer.parseInt(bandwidth);
	 			  }
	 			else if(Protocol.equals("DHMIP"))
	 			  {
	 				
	 			 txt8.setText(bandwidth);
	 			 txt9.setText(Timedelay);
	 			 txt10a.setText(Protocol);
	 			 txt10.setText(Filesize);
	 			 //mhmip= Integer.parseInt(bandwidth);
	 			  }
	 			   
	 			
	            }
	            // s.executeUpdate("truncate table Mobility");
				/*
				 * Connection c = (Connection) DriverManager.getConnection("jdbc:odbc:Mobile");
				 
				Statement s = c.createStatement();
				s.executeUpdate("insert into Mobile values('"+bandwidth+"','"+Timedelay+"','"+Protocol+"','"+Filesize+"')");
				*/
			} catch (Exception e1) {
				
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			
			
			
			
			
		 }
	 }
	 
	
}
